package cn.tedu.commonUtils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private Boolean success;
    private String msg;
    private Integer state;
    private Map<String,Object> data = new HashMap<>();

    private R(){};

    public static R ok(){
        R r = new R();
        r.setState(ResultState.SUCCESS);
        r.setSuccess(true);
        r.setMsg("success");
        return r;
    }

    public static R error(){
        R r = new R();
        r.setState(ResultState.ERROR);
        r.setSuccess(false);
        r.setMsg("error");
        return r;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public R state(Integer state) {
        this.setState(state);
        return this;
    }

    public R msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public R data(String key,Object value) {
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String,Object> map) {
        this.setData(map);
        return this;
    }
}
